function gewSocket(server_add,port,isEncrypted)
{
  if(isEncrypted==undefined)
    this.isEncrypted = false;
  else
    this.isEncrypted = isEncrypted;
  if(this.isEncrypted)
    var protocol ="wss://";
  else
    var protocol ="ws://";
  this.url = protocol+server_add+":"+port;
  this.webSocket = null;  
  // Callback func
  this.onOpenCallbackFunc = null;
  this.onMessageCallbackFunc = null;
  this.onErrorCallbackFunc = null;
  this.onCloseCallbackFunc = null;
}
gewSocket.prototype = {
  connect: function(){
    this.webSocket = new WebSocket(this.url);
    var ws = this.webSocket;
    ws.onopen = this.onOpenCallbackFunc;
    ws.onmessage = this.onMessageCallbackFunc;
    ws.onerror = this.onErrorCallbackFunc;
    ws.onclose = this.onCloseCallbackFunc;
  },
  send:function(data){
    if(this.webSocket&& this.webSocket.readyState==GEW_SOCKET_OPEN)
      this.webSocket.send(data);
  },
  close:function(){
    if(this.webSocket)
      this.webSocket.close();
  },
  getStatus:function(){
    if(this.webSocket==null)
      return GEW_SOCKET_NOT_CREATED;
    else
      return this.webSocket.readyState;
  },
  getBufferedAmount:function(){
    if(this.webSocket)
      return this.webSocket.bufferedAmount;
    return 0;
  }
}
